package com.example.zyl.common.listener.impl;


import com.example.zyl.common.enums.RedisQueueEnum;
import com.example.zyl.common.listener.RedisDelayedQueueListener;
import com.example.zyl.common.query.query.RedisQueueMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RedisQueueListener implements RedisDelayedQueueListener<RedisQueueMessage> {

    @Override
    public void invoke(RedisQueueMessage message) {
        RedisQueueEnum queueEnum = message.getQueueEnum();
        log.info("监听到消息队列名称 ==> [{}]", queueEnum.getQueueName());
        StopWatch stopWatch = new StopWatch();
        // 开始计时
        queueEnum.startLog(stopWatch);
        // 执行业务逻辑
        queueEnum.execute(message.getMessage());
        // 结束计时
        queueEnum.endLog(stopWatch);
    }
}
